package l1j.opqlo.NewSystem.ItemLevelUp;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;

import l1j.server.server.model.Instance.L1ItemInstance;

public class LevelStatus {

	private short _addstr = 0;
	private short _adddex = 0;
	private short _addint = 0;
	private short _addwis = 0;
	private short _addcon = 0;
	private int _dmg = 0;
	private int _hitModifier = 0;
	private int _dmgModifier = 0;
	private int _sp = 0;
	private int _mr = 0;
	private int _extradmg = 0;
	private int _extradef = 0;
	private int _fixdamage = 0;
	private int _randomdamage = 0;
	private int _magicdmgmodifier = 0;
	private int _dmgreduction = 0;
	private int _hp = 0;
	private int _hpr = 0;
	private int _mp = 0;
	private int _mpr = 0;
	private double 掉寶率 = 0;
	private double 金幣率 = 0;
	private boolean _cansee = false;

	// 1=地、2=火、4=水、5=光、6=闇、8=風
	private final Map<Integer, Integer> _attrDmg = new HashMap<Integer, Integer>();

	// 0=普通、1=不死系、2=惡魔系、3=BOSS系、4=亡靈系、5=狼人系、6=龍系、7=人類
	private Map<Integer, Integer> _ethnicity;
	// 順序: 力=0敏=1智=2精=3體=4魅=5
	private final Map<Integer, Short> _status = new HashMap<Integer, Short>();
	private final static String TOKEN = ":";

	/** opqlo 道具升級系統 */
	public void AddLvCon(final short s) {
		this._addcon += s;
	}

	/** opqlo 道具升級系統 */
	public void AddLvDex(final short s) {
		this._adddex += s;
	}

	/** opqlo 道具升級系統 */
	public void AddLvDmg(final int i) {
		this._dmg += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvDmgModifier(final int i) {
		this._dmgModifier += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvDmgReduction(final int i) {
		this._dmgreduction += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvExtraDef(final int i) {
		this._extradef += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvExtraDmg(final int i) {
		this._extradmg += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvFixDmg(final int i) {
		this._fixdamage += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvHitModifier(final int i) {
		this._hitModifier += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvHp(final int i) {
		this._hp += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvHpr(final int i) {
		this._hpr += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvInt(final short s) {
		this._addint += s;
	}

	/** opqlo 道具升級系統 */
	public void AddLvMagicDmgModifier(final int i) {
		this._magicdmgmodifier += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvMp(final int i) {
		this._mp += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvMpr(final int i) {
		this._mpr += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvMR(final int i) {
		this._mr += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvRandomDmg(final int i) {
		this._randomdamage += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvSP(final int i) {
		this._sp += i;
	}

	/** opqlo 道具升級系統 */
	public void AddLvStr(final short s) {
		this._addstr += s;
	}

	/** opqlo 道具升級系統 */
	public void AddLvWis(final short s) {
		this._addwis += s;
	}

	public void Add金幣率(final int i) {
		this.金幣率 += i / 100D;
	}

	public void Add掉寶率(final int i) {
		this.掉寶率 += i / 100D;
	}

	/** 屬性列表是否為空 */
	public boolean AttrIsNull() {

		if (this._attrDmg == null) {
			return true;
		}
		return false;
	}

	/** 種族列表是否為空 */
	public boolean EthnicityIsNull() {

		if (this._ethnicity == null) {
			return true;
		}
		return false;
	}

	/** 屬性傷害取得 */
	public double getAttrDmg(final int attr) {

		if (this._attrDmg == null) {
			return 0;
		}

		if (this._attrDmg.get(attr) == null) {
			return 0;
		}
		return this._attrDmg.get(attr) / 100D;
	}

	/**
	 * 種族傷害取得 0=普通、1=不死系、2=惡魔系、3=BOSS系、4=亡靈系、5=狼人系、6=龍系、7=人類
	 */
	public double getEthnicityDmg(final int type) {
		if (this._ethnicity == null) {
			return 0;
		}
		if (this._ethnicity.get(type) == null) {
			return 0;
		}
		return this._ethnicity.get(type) / 100D;
	}

	/** opqlo 道具升級系統 */
	public short getLvCon() {
		return this._addcon;
	}

	/** opqlo 道具升級系統 */
	public short getLvDex() {
		return this._adddex;
	}

	/** opqlo 道具升級系統 */
	public int getLvDmg() {
		return this._dmg;
	}

	/** opqlo 道具升級系統 */
	public int getLvDmgModifier() {
		return this._dmgModifier;
	}

	/** opqlo 道具升級系統 */
	public int getLvDmgReduction() {
		return this._dmgreduction;
	}

	/** opqlo 道具升級系統 */
	public int getLvExtraDef() {
		return this._extradef;
	}

	/** opqlo 道具升級系統 */
	public int getLvExtraDmg() {
		return this._extradmg;
	}

	/** opqlo 道具升級系統 */
	public int getLvFixDmg() {
		return this._fixdamage;
	}

	/** opqlo 道具升級系統 */
	public int getLvHitModifier() {
		return this._hitModifier;
	}

	/** opqlo 道具升級系統 */
	public int getLvHp() {
		return this._hp;
	}

	/** opqlo 道具升級系統 */
	public int getLvHpr() {
		return this._hpr;
	}

	/** opqlo 道具升級系統 */
	public short getLvInt() {
		return this._addint;
	}

	/** opqlo 道具升級系統 */
	public int getLvMagicDmgModifier() {
		return this._magicdmgmodifier;
	}

	/** opqlo 道具升級系統 */
	public int getLvMp() {
		return this._mp;
	}

	/** opqlo 道具升級系統 */
	public int getLvMpr() {
		return this._mpr;
	}

	/** opqlo 道具升級系統 */
	public int getLvMR() {
		return this._mr;
	}

	/** opqlo 道具升級系統 */
	public int getLvRandomDmg() {
		return this._randomdamage;
	}

	// opqlo 道具升級系統END

	/** opqlo 道具升級系統 */
	public int getLvSP() {
		return this._sp;
	}

	/** opqlo 道具升級系統 */
	public short getLvStr() {
		return this._addstr;
	}

	/** opqlo 道具升級系統 */
	public short getLvWis() {
		return this._addwis;
	}
	private final HashMap<Integer , Double> _attrDef = new HashMap<Integer , Double>();

	/** 風剋水 、 水剋火、 火剋地、地剋風  */
	public void setAttrDef(final int type , final double value){
		
		switch(type){
		case 1://地
			_attrDef.put(1 , value);
			break;

		case 2://火
			_attrDef.put( 2,value);
			break;

		case 4://水
			_attrDef.put( 4, value);
			break;
		case 5://光
			_attrDef.put( 5,value);
			break;
		case 6://闇
			_attrDef.put(6, value);
			break;
		case 8://風
			_attrDef.put(8,value);
			break;
		}
	}
	
	public HashMap<Integer , Double> getAttrDef(){
		return _attrDef;
	}
	public double getAttrDef(final int type){
		if(_attrDef.containsKey(type)){
			return _attrDef.get(type);
		}
		return 0;
	}


	/**
	 * 六屬性加成取得 順序: 力=0敏=1智=2精=3體=4魅=5
	 */
	public short getStatus(final int status) {

		if (this._status == null) {
			return 0;
		}
		if (this._status.get(status) == null) {
			return 0;
		}
		return this._status.get(status);
	}

	public double get金幣率() {
		return this.金幣率;
	}

	public double get掉寶率() {
		return this.掉寶率;
	}

	/** opqlo 道具升級系統 */
	public boolean isCanSee() {
		return this._cansee;
	}

	/** opqlo 道具升級系統 */
	public void isCanSee(final boolean i) {
		this._cansee = i;
	}

	/** 重置所有數值 */
	public void Reset() {
		this._addstr = 0;
		this._adddex = 0;
		this._addint = 0;
		this._addwis = 0;
		this._addcon = 0;
		this._dmg = 0;
		this._hitModifier = 0;
		this._dmgModifier = 0;
		this._sp = 0;
		this._mr = 0;
		this._extradmg = 0;
		this._extradef = 0;
		this._fixdamage = 0;
		this._randomdamage = 0;
		this._magicdmgmodifier = 0;
		this._dmgreduction = 0;
		this._hp = 0;
		this._hpr = 0;
		this._mp = 0;
		this._mpr = 0;
		this.掉寶率 = 0;
		this.金幣率 = 0;
	}

	/**
	 * 特殊傷害儲存 0=四屬性攻擊 1=能力加成 2=種族傷害加成
	 * */
	public String saveItemSpecialDmg(final int type) {
		final StringBuilder log = new StringBuilder();

		switch (type) {

		/**屬性攻擊加成 1地、2火、4水、5光、6闇、8風**/
		case 0:
			int earth = 0,
			fire = 0,
			water = 0,
			wind = 0,
			light =0,
			dark =0;
			if (this._attrDmg != null) {

				final Iterator<Integer> attrkey = this._attrDmg.keySet().iterator();
				while (attrkey.hasNext()) {
					final int key = attrkey.next();

					switch (key) {
					case 1:
						earth = this._attrDmg.get(key);
						break;
					case 2:
						fire = this._attrDmg.get(key);
						break;
					case 4:
						water = this._attrDmg.get(key);
						break;
					case 5:
						light = this._attrDmg.get(key);
						break;
					case 6:
						dark = this._attrDmg.get(key);
						break;
					case 8:
						wind = this._attrDmg.get(key);
						break;
					}
				}
			}
			log.append(earth).append(TOKEN).append(fire).append(TOKEN)
			.append(water).append(TOKEN).append(wind).append(TOKEN)
			.append(light).append(TOKEN).append(dark);
			break;

		case 1:// 六屬性加成
			final int[] list = { 0, 0, 0, 0, 0, 0 };
			if (this._status != null) {
				final Iterator<Integer> statuskey = this._status.keySet()
						.iterator();
				while (statuskey.hasNext()) {
					final int key = statuskey.next();
					list[key] = this._status.get(key);
				}

			}
			final int size = list.length;
			for (int s = 0; s < size; s++) {
				log.append(list[s]);
				if (s < size - 1) {
					log.append(TOKEN);
				}
			}
			break;

		case 2:

			// 0=普通、1=不死系、2=惡魔系、3=BOSS系、4=亡靈系、5=狼人系、6=龍系、7=人類
			int normal = 0,
			undead = 0,
			diablo = 0,
			boss = 0,
			ghost = 0,
			wolf = 0,
			dragon = 0,
			humen = 0;
			if (this._ethnicity != null) {
				final Iterator<Integer> skey = this._ethnicity.keySet()
						.iterator();
				while (skey.hasNext()) {
					final int key = skey.next();
					switch (key) {
					case 0:
						normal = this._ethnicity.get(key);
						break;
					case 1:
						undead = this._ethnicity.get(key);
						break;
					case 2:
						diablo = this._ethnicity.get(key);
						break;
					case 3:
						boss = this._ethnicity.get(key);
						break;
					case 4:
						ghost = this._ethnicity.get(key);
						break;
					case 5:
						wolf = this._ethnicity.get(key);
						break;
					case 6:
						dragon = this._ethnicity.get(key);
						break;
					case 7:
						humen = this._ethnicity.get(key);
						break;
					}
				}
			}
			log.append(normal).append(TOKEN).append(undead).append(TOKEN)
			.append(diablo).append(TOKEN).append(boss).append(TOKEN)
			.append(ghost).append(TOKEN).append(wolf).append(TOKEN)
			.append(dragon).append(TOKEN).append(humen);

			break;
		}

		return log.toString();

	}

	/** 屬性傷害設定 */
	public void setAttrDmg(final int attr, final int value) {
		int values = 0;
		if (value != 0) {
			values = value;
		}

		this._attrDmg.put(attr, values);

	}

	/**
	 * 種族傷害設定 0=普通、1=不死系、2=惡魔系、3=BOSS系、4=亡靈系、5=狼人系、6=龍系、7=人類
	 */
	public void setEthnicityDmg(final int type, final int value) {
		int values = 0;
		if (value != 0) {
			values = value;
		}

		if (this._ethnicity == null) {
			this._ethnicity = new HashMap<Integer, Integer>();
		}
		this._ethnicity.put(type, values);
	}

	/** 特殊傷害讀取 */
	public void setItemSpecialDmg(final L1ItemInstance item, final String s,final int type) {
		final StringTokenizer st = new StringTokenizer(s, TOKEN);
		final int iSize = st.countTokens();
		String sTemp = null;

		switch (type) {

		case 0:// 屬性傷害

			final int[] iReturn = new int[iSize];
			for (int is = 0; is < iSize; is++) {
				sTemp = st.nextToken();
				iReturn[is] = Integer.parseInt(sTemp);
			}
			// 地:1
			this.setAttrDmg(1, iReturn[0]);

			// 火:2
			this.setAttrDmg(2, iReturn[1]);

			// 水:4
			this.setAttrDmg(4, iReturn[2]);

			// 風:8
			this.setAttrDmg(8, iReturn[3]);
			if(iSize>4){ 
				this.setAttrDmg(5, iReturn[4]);
				this.setAttrDmg(6, iReturn[5]);
			}else{
				this.setAttrDmg(5, 0);
				this.setAttrDmg(6, 0);	
			}

			break;

		case 1: // 六屬性加成

			for (int is = 0; is < iSize; is++) {
				sTemp = st.nextToken();
				this.setStatus(is, Short.parseShort(sTemp));
			}
			break;

		case 2: // 種族增傷 0=普通、1=不死系、2=惡魔系、3=BOSS系、4=亡靈系、5=狼人系、6=龍系、7=人類
			for (int is = 0; is < iSize; is++) {
				sTemp = st.nextToken();
				this.setEthnicityDmg(is, Integer.parseInt(sTemp));
			}
			break;
		}
	}

	/**
	 * 六屬性加成設定 順序: 力=0敏=1智=2精=3體=4魅=5
	 */
	public void setStatus(final int type, final short value) {

		this._status.put(type, value);
	}

	/** 數值列表是否為空 */
	public boolean StatusIsNull() {

		if (this._status == null) {
			return true;
		}
		return false;
	}

}
